#include "multi_button_task.h"
#include "multi_button.h"
#include "bsp_key.h"


#define DETECT_MODE 0



#if DETECT_MODE
static void multi_button_task_time_handler(void * p_context)
{
	button_ticks();
}
#else

static void multi_button_task(void *pvParameters)
{
	static TickType_t tick;
	tick = xTaskGetTickCount();
    while(1)
    {
		button_ticks();
		vTaskDelayUntil(&tick, pdMS_TO_TICKS(20));
		//vTaskDelay(10 / portTICK_PERIOD_MS);
    }
}

#endif

esp_err_t multi_button_task_init(void)
{

	multi_button_task_debug("初始化...");
	//bsp_key_init();

#if DETECT_MODE
	esp_timer_handle_t multi_button_task_timer_id = NULL;
	esp_timer_create_args_t multi_button_task_timer_conf = {
			.callback = multi_button_task_time_handler,
			.name     = "multi_button_task_timer"
	};

	esp_timer_create(&multi_button_task_timer_conf, &multi_button_task_timer_id);
	esp_timer_start_periodic(multi_button_task_timer_id, 5 * 1000U);
#else
    xTaskCreate(multi_button_task, "multi button task", 1024*5, NULL, configMAX_PRIORITIES-2, NULL);
#endif

	multi_button_task_debug("初始化成功");
	return ESP_OK;
}
